package com.lysj.merchant.desk.feignImpl;

import com.lysj.admin.common.merchant.domain.ComDeskVo;
import com.lysj.admin.common.merchant.feign.DeskServiceFeign;
import com.lysj.admin.utils.web.ParamUtil;
import com.lysj.merchant.desk.domain.Desk;
import com.lysj.merchant.desk.domain.TeaCharge;
import com.lysj.merchant.desk.service.DeskService;
import com.lysj.merchant.desk.service.TeaChargeService;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ Author ：drj.
 * @ Date  ：Created in 10:37 2019/3/22
 * @ Description:
 **/
@RestController
public class DeskServiceFeignImpl implements DeskServiceFeign {

    @Resource
    private DeskService deskService;

    @Resource
    private TeaChargeService teaChargeService;

    //下单改变餐桌状态
    @Override
    public boolean changeDeskStatus(String deskId, Integer status) {
        Desk desk = deskService.findOne(deskId);
        desk.setStatus(status);
        deskService.save(desk);
        return true;
    }

    //用户付完款,清空用餐人数,用户id,餐桌状态变为空闲
    @Override
    public boolean initDesk(String deskId) {
        Desk desk = deskService.findOne(deskId);
        desk.setCusNumber(0);
        desk.setCustomerId("");
        desk.setStatus(Desk.Status.FREE.getCode());
        deskService.save(desk);
        return true;
    }

    @Override
    public Map<String, String> getAllDeskName() {
        Map<String, String> map = new HashMap<>();
        List<Desk> deskList = deskService.getRepository().findAll();
        for (Desk desk : deskList) {
            map.put(desk.getId(), desk.getName());
        }
        return map;
    }

    @Override
    public BigDecimal getStoreTeaCharge(String storeId) {
        TeaCharge teaCharge = teaChargeService.getRepository().findByStoreId(storeId);
        return null == teaCharge ? BigDecimal.ZERO : teaCharge.getMoney();
    }


}
